package functional;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.function.Predicate;

/**
 * Author:ZouHeng
 * Description:
 * Date:2021-07-05  14:08
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PredicateDemo {

    private String message;

    public void judgeMsg(Predicate<String> predicate) {
        boolean veryLong = predicate.test(this.message);
        System.out.println("字符串很长吗：" + veryLong);
    }

    public void judgeMsgAnd(Predicate<String> one, Predicate<String> two) {
        boolean valid = one.and(two).test(this.message);
        System.out.print("字符串是否符合要求：" + valid);
    }

    public void judgeMsgOr(Predicate<String> one, Predicate<String> two) {
        boolean valid = one.or(two).test(this.message);
        System.out.print("字符串是否符合要求：" + valid);
    }

    public void judgeMsgnegate(Predicate<String> one) {
        boolean valid = one.negate().test(this.message);
        System.out.print("字符串是否符合要求：" + valid);
    }

    public void filter(Predicate<String> one, Predicate<String> two, String[] array) {
        for (String item: array) {
            if (one.and(two).test(item)) {
                System.out.println(item);
            }
        }
    }
}
